package com.gitee.wsl.math.random

import kotlin.random.Random


/**
 * Returns true with a chance of [chance].
 *
 * @param chance the chance of returning true (0.0-100.0)
 * @return true with a chance of [chance]
 */
fun Random.chance(chance: Double): Boolean {
    require(chance in 0.0..100.0) { "chance must be between 0.0 and 100.0" }
    return randomBigPercent() < chance
}

/**
 * Executes [block] with a chance of [chance].
 *
 * @param chance the chance of executing [block] (0.0-100.0)
 * @param block the block to execute
 */
 inline fun Random.chance(chance: Double, block: () -> Unit) {
    if (chance(chance)) block()
}